﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Web;

namespace HotelSoftBusWeb
{
    public class WebSocket
    {
        Thread listenThread;

        public void Start()
        {
            listenThread = new Thread(BeginListen);

            listenThread.Start();
        }

        private void BeginListen()
        {

            IPAddress ServerIp = IPAddress.Parse("127.0.0.1");

            IPEndPoint iep = new IPEndPoint(ServerIp, 8033);

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            byte[] byteMessage = new byte[1024];

            socket.Bind(iep);

            while (true)
            {

                try
                {

                    socket.Listen(10);

                    Socket newSocket = socket.Accept();

                    newSocket.Receive(byteMessage);

                    string msg = null;

                    msg += newSocket.RemoteEndPoint.ToString() + Encoding.Default.GetString(byteMessage);

                    string ss = msg.Trim();

                }

                catch (SocketException ex)
                {
                    
                }

            }

            // while(byteMessage!=null);
        }
    }
}